package com.example.lianjuan.ui.custom;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewParent;
import android.widget.FrameLayout;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.viewpager.widget.ViewPager;
import androidx.viewpager2.widget.ViewPager2;


public class customNestedScrollble extends FrameLayout {

    public customNestedScrollble(@NonNull Context context) {
        super(context);
    }

    public customNestedScrollble(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public customNestedScrollble(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent ev) {
    //内部拦截法,拦截最外层的ViewPage2,只给内层的ViewPager2消费
        if (getParent() != null && ev.getAction() == MotionEvent.ACTION_DOWN) {
            getParent().requestDisallowInterceptTouchEvent(true);
        }
        return super.dispatchTouchEvent(ev);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        return super.onInterceptTouchEvent(ev);
    }
}